﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace Program16GDI
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 画直线
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnLine_Click(object sender, EventArgs e)
        {
            //创建GDI对象
            Graphics g = this.CreateGraphics();

            //创建画笔对象
            Pen pen = new Pen(Brushes.DarkRed,2);

            //个性线条   点点
            //pen.DashStyle = DashStyle.Dot;

            float[] dashValues = { 2, 4, 8, 16 };
            pen.DashPattern = dashValues;


            //画直线，建立坐标;
            Point p1 = new Point(30, 50);
            Point p2 = new Point(300, 50);


            //画直线
            g.DrawLine(pen, p1, p2);

        }

        private void btnRect_Click(object sender, EventArgs e)
        {

            //创建GDI对象
            Graphics g = this.CreateGraphics();

            //创建画笔对象
            Pen pen = new Pen(Brushes.DarkGreen, 2);

            //定义矩形大小
            Size size = new Size(100, 100);

            //矩形的坐标
            Point startPoint = new Point(30, 60);

            //定义矩形
            Rectangle rect = new Rectangle(startPoint, size);

            g.DrawRectangle(pen, rect);
        }

        private void btnCircle_Click(object sender, EventArgs e)
        {
            //创建GDI对象
            Graphics g = this.CreateGraphics();

            //创建画笔对象
            Pen pen = new Pen(Brushes.DarkOrange, 2);


            g.DrawEllipse(pen, 40, 170, 200, 100);  //前两个是坐标 
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // 创建GDI对象
            Graphics g = this.CreateGraphics();

            //创建画笔对象
            SolidBrush pen = new SolidBrush(Color.Red);
            g.FillPie(pen, 100, 250, 200, 200, 45, 90);

             pen = new SolidBrush (Color.Black);
            g.FillPie(pen, 100, 250, 200, 200, 135, 90);

            pen = new SolidBrush(Color.Blue);
            g.FillPie(pen, 100, 250, 200, 200, 225, 20);

        }

        private int i = 0; 

        //当前窗体绘图时触发
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            i++;
            lblCount.Text = i.ToString();
        }

        private void label1_Click(object sender, EventArgs e)
        {
            label1.Text = ValidetaCode.CreateVCode(4);
        }
    }
}
